<?php
	class WS_Pagination {
		
		public function __construct() {
			
		}
		
		public function numPerRow($pageRows) {
			return $pageRows; 
		}
		
		public function lastCeilPerRow($queryCount, $pageRows) {
			return ceil( $queryCount/$pageRows ); 
		}
		
		public function pageNumRow($pageNum, $last) {
		
			if ( !(isset($pageNum)) )
				$pageNum = 1;
	
			if ($pageNum < 1) { 
				$pageNum = 1; 
			}
			elseif ($pageNum > $last) { 
				$pageNum = $last; 
			}
			return ($pageNum);
		}
		
		public function limitRow($pageNum, $pageRows) {
			
			$pageNum 	= escapestring($pageNum);
			$pageRows 	= escapestring($pageRows);
			
			return " LIMIT " . ($pageNum - 1) * $pageRows . "," .$pageRows;
		}
		
		public function pagination($arrBut, $pageNum, $last, $classCSS = '', $urlGetLink = '') {
			
			if ( !empty($urlGetLink) ) {
				$urlGet = http_build_query($urlGetLink) . '&';
			}

			if ( $last != 0) {
				$pagination = "<span class='" . $classCSS['label'] . "'>Page ".$pageNum." of ".$last."</span> ";
				
				if ($pageNum == 1) {
					$pagination .= '<span class="pagination-grey">' . $arrBut['first'] . '</span><span class="pagination-grey">' . $arrBut['previous'] . '</span>';
				}
				else  {
					$pagination .= "<a href='?".$urlGet."page_no=1'  class='" . $classCSS['button'] . "'>" . $arrBut['first'] . "</a>";
					$previous = $pageNum - 1;
					$pagination .= "<a href='?".$urlGet."page_no=".$previous."'  class='" . $classCSS['button'] . "'>" . $arrBut['previous'] . "</a>";
				} 
				
				if ($pageNum == $last) {
					$pagination .= '<span class="pagination-grey">' . $arrBut['next'] . '</span><span class="pagination-grey">' . $arrBut['last'] . '</span>';
				} 
				else {
					$next = $pageNum + 1;
					$pagination .= "<a href='?".$urlGet."page_no=".$next."' class='" . $classCSS['button'] . "'>" . $arrBut['next'] . "</a>";
					$pagination .= "<a href='?".$urlGet."page_no=".$last."' class='" . $classCSS['button'] . "'>" . $arrBut['last'] . "</a>";
				}
			}
			
			return $pagination;
		}
	}
?>